<template>
    <div>
    <Modal :title="modalTitle" v-model="modalVisible" :mask-closable='false' :width="650" :styles="{top: '100px'}">
        <Form ref="feedbackForm" :model="feedbackForm" :label-width="70" :rules="formValidate">
            <FormItem label="反馈内容" prop="content">
                <Input v-model="feedbackForm.content" disabled autocomplete="off"/>
            </FormItem>

            <FormItem label="回复内容" prop="title">
                <Input v-model="feedbackForm.title" type="textarea" autocomplete="off"/>
            </FormItem>
        </Form>
        <div slot="footer">
            <Button type="text" @click="cancelUser">取消</Button>
            <Button type="primary" :loading="submitLoading" @click="handelSubmit">提交</Button>
        </div>
    </Modal>
    </div>
</template>

<script>
    import {add, edit,getfeedback} from "@/api/feedback";
    export default {
        name: "feedbackDrawer",
        components: {

        },
        data() {
            return {
                type:0,
                errorPass: "",
                deptLoading: false,
                modalTitle: "留言回复",
                submitLoading: false,
                modalVisible: false,
                feedbackForm: {
                    id:"",
                    title: "",
                    content:""
                },
                formValidate: {
                    title: [{required: true, message: "回复内容不能为空", trigger: "blur"}]
                }
            }
        },
        methods: {
            init() {

            },
            getData() {
                this.loading = true;
                getfeedback(this.feedbackForm.id).then(res => {
                    this.loading = false;
                    if (res.status === true) {
                        this.feedbackForm = res.data;
                    }
                });
            },
            showDrawer(params) {
                this.modalVisible = true;
                if (params.id) {
                    this.type = 1;
                    this.modalTitle = "留言回复";
                    this.feedbackForm.id=params.id;
                    this.getData();
                }
            },
            cancelUser() {
                this.modalVisible = false;
            },
            handelSubmit() {
                this.$refs.feedbackForm.validate(valid => {
                    if (valid) {
                        this.submitLoading = true;
                        this.feedbackForm.vipConfigItems=JSON.stringify(this.feedbackForm.items);
                        if (this.type === 0) {
                            // 添加 避免编辑后传入id等数据 记得删除
                            delete this.feedbackForm.id;
                            add(this.feedbackForm).then(res => {
                                this.submitLoading = false;
                                if (res.status === true) {
                                    this.$Message.success("添加成功");
                                    this.$parent.getDataList();
                                    this.modalVisible = false;
                                }
                            });
                        } else if(this.type === 1){
                            // 编辑
                            edit(this.feedbackForm).then(res => {
                                this.submitLoading = false;
                                if (res.status === true) {
                                    this.$Message.success("修改成功");
                                    this.$parent.getDataList();
                                    this.modalVisible = false;
                                }
                            });
                        }
                    }
                });
            }
        },
        mounted() {

        }
    }
</script>

<style>

</style>